package com.character.controller;

import com.character.entity.Color;
import com.character.entity.MyReturn;

import com.character.entity.Time;
import com.character.service.ResultVoService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author 张燕豪
 * @description
 * @date 2021/12/7
 */
@RestController
@RequestMapping("resultOne")
public class ShowPie extends BaseController{
    @Resource
    private ResultVoService resultVoService;
    @GetMapping("getNum")
    public MyReturn selectAll() {
        Color color =resultVoService.resultAll();
        String[] name= {"红色性格","黄色性格","蓝色性格","绿色性格"};
        Integer[] value={color.getRed(),color.getYellow(),color.getBlue(),color.getGreen()};
        List<Map> list=new ArrayList<>();
        for (int i = 0; i < name.length; i++) {
            Map map=new HashMap();
            map.put("value",value[i]);
            map.put("name",name[i]);
            list.add(map);
        }
        return super.success(list);
    }
    @GetMapping("getNum1")
    public MyReturn selectAll1() {
        List<Time> list= resultVoService.theCount();
        Integer[] sum = new Integer[list.size()];
        String[] dd=new String[list.size()];
        int i=0;
        for(Time time:list){
            dd[i]=time.getMonth()+"月"+time.getDay()+"日";
            sum[i]=time.getSum();
            i++;
        }
        Object[] obj ={dd,sum};
        return super.success(obj);
    }
    @GetMapping("getOne")
    public MyReturn selectOne(Integer id) {
        Color color =resultVoService.resultOne(id);
        String[] name= {"红色性格","黄色性格","蓝色性格","绿色性格"};
        Integer[] value={color.getRed(),color.getYellow(),color.getBlue(),color.getGreen()};
        List<Map> list=new ArrayList<>();
        for (int i = 0; i < name.length; i++) {
            Map map=new HashMap();
            map.put("value",value[i]);
            map.put("name",name[i]);
            list.add(map);
        }
        return super.success(list);
    }
}
